package com.avic.rong.questionOrAnswer.imgSelect;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * ================================================
 * 作    者：Weirdo_lin
 * 版    本：1.0
 * 创建日期：2018/4/25
 * 描    述：多选图片间距
 * ================================================
 */
public class PictureSpacingDecoration extends RecyclerView.ItemDecoration {

    private int spacing;

    public PictureSpacingDecoration(int spacing) {
        this.spacing = spacing;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        int column = position % 3;

        if (column == 0) {
            outRect.left = spacing;
        } else if (column == 2) {
            outRect.right = spacing;
        } else {
            outRect.left = spacing / 2;
            outRect.right = spacing / 2;
        }

        outRect.top = spacing / 2;
    }
}